package com.mxin.ui.base

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import androidx.lifecycle.LifecycleOwner
import com.mxin.ui.global.GlobalViewManager

abstract class BaseFragment : Fragment() , IBaseView{

    private lateinit var loadingDialog: Dialog

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initView()
        initData()
    }

    override fun finishActivity() {
        requireActivity().finish()
    }

    override fun getLifeCycleOwner(): LifecycleOwner {
        return viewLifecycleOwner
    }

    override fun getContext(): Context {
        return super.getContext()!!
    }

    override fun showLoadingView(init:((Dialog)->Unit)?) {
        if(!::loadingDialog.isInitialized){
            loadingDialog = GlobalViewManager.createLoadingView(context)
        }
        init?.invoke(loadingDialog)
        loadingDialog.show()
    }

    override fun dismissLoadingView() {
        if(::loadingDialog.isInitialized){
            loadingDialog.dismiss()
        }
    }


}